package com.kfm.servlet.day04;

import com.kfm.servlet.day04.db.DBUtils;
import com.kfm.servlet.day04.model.FileModel;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/filelistv2")
public class FileListPageServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 查询数据库，获取文件列表
        // 获取所有的文件
        DBUtils<FileModel> dbUtils = new DBUtils<>(1);

        String sql = "select id, path, type, name, size, upload_time from file";
        List<FileModel> select = dbUtils.select(sql, FileModel.class);

        // 把文件列表放到 request 中
        req.setAttribute("files", select);

        req.getRequestDispatcher("/WEB-INF/pages/filelist.jsp").forward(req, resp);
    }
}
